home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 October / MACPOWER-1997-10.ISO.7z / MACPOWER-1997-10.ISO / AMUG / PROGRAMMING / Mac F2C 1.3.5.sit / Mac F2C 1.3.5 / Test Project ƒ / F2Cmain.cp < prev    next >
Text File  |  1997-03-27  |  5KB  |  241 lines

  1. /* STARTUP PROCEDURE FOR TRANSLATED FORTRAN PROGRAMS */
  2.  
  3. /* IMT 9Sep95  Modified for new conditional compile mechanism */
  4. #if ( defined(THINK_C) || defined(THINK_CPLUS) )
  5. #define TPM_F2C            
  6. #endif
  7.  
  8. /* IMT 9Sep95  Modified for new conditional compile mechanism */
  9. #if (  defined(SYMANTEC_C) || defined(SYMANTEC_CPLUS) )
  10. #define SPM_F2C
  11. #endif
  12.  
  13. /* IMT 9Sep95  Modified for new conditional compile mechanism */
  14. /* DF  26Mar97 added MrC */
  15. #if ( (!defined(MPW_CW_F2C) && defined(__MWERKS__)) || defined(__MRC__) )
  16. #define CW_F2C
  17. #endif
  18.  
  19. /* IMT 9Sep95  THINK Project Manager specific includes */
  20. #ifdef TPM_F2C
  21. #include <console.h>
  22. #endif                    
  23.  
  24. /* IMT 9Sep95  Symantec Project Manager specific includes */
  25. #ifdef SPM_F2C 
  26. #include <console.h>    
  27. #endif                    
  28.  
  29. /* IMT 9Sep95  CodeWarrior specific includes */
  30. #ifdef CW_F2C
  31. #include <console.h>
  32. #include <SIOUX.h>
  33. #endif
  34.  
  35. /* IMT 9Sep95  MPW CodeWarrior specific includes */
  36. #ifdef MPW_CW_F2C
  37. #include <console.h>
  38. #endif
  39.  
  40.  
  41. /* IMT 12Apr96  Include files for adjusting the stack size in 68K */
  42. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  43. #if GENERATING68K
  44. #include <ConditionalMacros.h>
  45. #include <LowMem.h>
  46. #include <Memory.h>
  47. #endif /* GENERATING68K */
  48. #endif /* Macintosh C compilers */
  49.  
  50.  
  51. /* IMT 09Sep95  Prototypes for new functions that add multitasking */
  52. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. void InitMultiTask( long sliceInMicroSecs );
  57. void EndMultiTask( void );
  58. #ifdef __cplusplus
  59. }
  60. #endif
  61. #endif /* Macintosh C compilers */
  62.  
  63.  
  64. /* IMT 10Sep95  Declare jump buffer used to recover from exception exits & aborts */
  65. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  66. #include <setjmp.h>
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif
  70. jmp_buf gRecoverToConsole;
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif /* Macintosh C compilers */
  75.  
  76.  
  77. #include "stdio.h"
  78. #include "signal.h"
  79.  
  80. #ifndef SIGIOT
  81. #ifdef SIGABRT
  82. #define SIGIOT SIGABRT
  83. #endif
  84. #endif
  85.  
  86.  
  87. #ifndef KR_headers
  88. #include "stdlib.h"
  89. #endif
  90. #ifdef __cplusplus
  91. extern "C" {
  92. #endif
  93.  
  94. #ifdef NO__STDC
  95. #define ONEXIT onexit
  96. extern void f_exit();
  97. #else
  98. #ifndef KR_headers
  99. extern void f_exit(void);
  100. #ifndef NO_ONEXIT
  101. #define ONEXIT atexit
  102. extern int atexit(void (*)(void));
  103. #endif
  104. #else
  105. #ifndef NO_ONEXIT
  106. #define ONEXIT onexit
  107. extern void f_exit();
  108. #endif
  109. #endif
  110. #endif
  111.  
  112. #ifdef KR_headers
  113. extern void f_init(), sig_die();
  114. extern int MAIN__();
  115. #define Int /* int */
  116. #else
  117. extern void f_init(void), sig_die(char*, int);
  118. extern int MAIN__(void);
  119. #define Int int
  120. #endif
  121.  
  122. static void sigfdie(Int n)
  123. {
  124. sig_die("Floating Exception", 1);
  125. }
  126.  
  127.  
  128. static void sigidie(Int n)
  129. {
  130. sig_die("IOT Trap", 1);
  131. }
  132.  
  133. #ifdef SIGQUIT
  134. static void sigqdie(Int n)
  135. {
  136. sig_die("Quit signal", 1);
  137. }
  138. #endif
  139.  
  140.  
  141. static void sigindie(Int n)
  142. {
  143. sig_die("Interrupt", 0);
  144. }
  145.  
  146. static void sigtdie(Int n)
  147. {
  148. sig_die("Killed", 0);
  149. }
  150.  
  151. #ifdef SIGTRAP
  152. static void sigtrdie(Int n)
  153. {
  154. sig_die("Trace trap", 1);
  155. }
  156. #endif
  157.  
  158.  
  159.  
  160. int xargc;
  161. char **xargv;
  162.  
  163. #ifdef KR_headers
  164. main(argc, argv) int argc; char **argv;
  165. #else
  166. main(int argc, char **argv)
  167. #endif
  168. {
  169.  
  170. /* IMT 12Apr96  Add conditional code to increase 68K stack size */
  171. /*              Adjust the following #define as needed */
  172. #define kDesiredStackSize  (40*1024L)     /* 68K stack size set to 40K bytes */
  173. #if GENERATING68K && defined(kDesiredStackSize)    
  174.     if ( kDesiredStackSize > LMGetDefltStack() )
  175.     {
  176.         Ptr newApplLimit = GetApplLimit() - (kDesiredStackSize - LMGetDefltStack());
  177.         SetApplLimit( newApplLimit );
  178.     }
  179. #endif    /* increase stack size */
  180.  
  181. /* IMT 09Sep95  Add file re-direction and command-line arguments dialog */
  182. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  183.     argc = ccommand( &argv );
  184. #endif /* Macintosh C compilers */
  185.  
  186. /* IMT 14Sep95  Initialize multi-tasking code */
  187. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  188.     InitMultiTask( 0 );
  189. #endif /* Multi-tasking code */
  190.  
  191. xargc = argc;
  192. xargv = argv;
  193. signal(SIGFPE, sigfdie);    /* ignore underflow, enable overflow */
  194. #ifdef SIGIOT
  195. signal(SIGIOT, sigidie);
  196. #endif
  197. #ifdef SIGTRAP
  198. signal(SIGTRAP, sigtrdie);
  199. #endif
  200. #ifdef SIGQUIT
  201. if(signal(SIGQUIT,sigqdie) == SIG_IGN)
  202.     signal(SIGQUIT, SIG_IGN);
  203. #endif
  204. if(signal(SIGINT, sigindie) == SIG_IGN)
  205.     signal(SIGINT, SIG_IGN);
  206. signal(SIGTERM,sigtdie);
  207.  
  208. #ifdef pdp11
  209.     ldfps(01200); /* detect overflow as an exception */
  210. #endif
  211.  
  212. f_init();
  213. #ifndef NO_ONEXIT
  214. ONEXIT(f_exit);
  215. #endif
  216.  
  217. /* IMT 10Sep95:  Set-up for returning to console from exceptional exits and aborts */
  218. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C)
  219. if ( setjmp(gRecoverToConsole) == 0 )
  220. #endif /* Macintosh C compilers */
  221.  
  222. MAIN__();
  223.  
  224. /* IMT 10Sep95:  Close out multi-tasking code for CW, SPM, TPM */
  225. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  226. EndMultiTask();
  227. puts( "¥nExecution complete.¥n" );
  228. #endif /* Macintosh C compilers */
  229.  
  230.  
  231. #ifdef NO_ONEXIT
  232. f_exit();
  233. #endif
  234. exit(0);    /* exit(0) rather than return(0) to bypass Cray bug */
  235. return 0;    /* For compilers that complain of missing return values; */
  236.             /* others will complain that this is unreachable code. */
  237. }
  238. #ifdef __cplusplus
  239.     }
  240. #endif
  241.